package com.openbravo.pos.reports;

import com.openbravo.basic.BasicException;
import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.loader.BaseSentence;
import com.openbravo.data.loader.SentenceList;
import com.openbravo.data.user.EditorCreator;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.forms.BeanFactoryApp;
import com.openbravo.pos.forms.BeanFactoryException;
import com.openbravo.pos.forms.DataLogicSales;
import com.openbravo.pos.forms.JPanelView;
import com.openbravo.pos.sales.TaxesLogic;
import com.openbravo.pos.util.JRViewer300;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JToggleButton;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;

public abstract class JPanelReport extends JPanel
  implements JPanelView, BeanFactoryApp
{
  private JRViewer300 reportviewer = null;
  private JasperReport jr = null;
  private EditorCreator editor = null;
  protected AppView m_App;
  protected SentenceList taxsent;
  protected TaxesLogic taxeslogic;
  private JButton jButton1;
  private JPanel jPanel1;
  private JPanel jPanelFilter;
  private JPanel jPanelHeader;
  private JToggleButton jToggleFilter;

  public JPanelReport()
  {
    initComponents();
  }

  public void init(AppView paramAppView)
    throws BeanFactoryException
  {
    this.m_App = paramAppView;
    DataLogicSales localDataLogicSales = (DataLogicSales)paramAppView.getBean("com.openbravo.pos.forms.DataLogicSales");
    this.taxsent = localDataLogicSales.getTaxList();
    this.editor = getEditorCreator();
    if ((this.editor instanceof ReportEditorCreator))
      this.jPanelFilter.add(((ReportEditorCreator)this.editor).getComponent(), "Center");
    this.reportviewer = new JRViewer300(null);
    add(this.reportviewer, "Center");
    try
    {
      InputStream localInputStream = getClass().getResourceAsStream(getReport() + ".ser");
     //  localObject;
	if (localInputStream == null)
      {
		// getreport=="/com/openbravo/reports/closedpos"   jyaokwe tsaqsyon
		JasperDesign  localObject = JRXmlLoader.load(getClass().getResourceAsStream(getReport() + ".jrxml"));
        this.jr = JasperCompileManager.compileReport((JasperDesign)localObject);
      }
      else
      {
        ObjectInputStream localObject = new ObjectInputStream(localInputStream);
        this.jr = ((JasperReport)((ObjectInputStream)localObject).readObject());
        ((ObjectInputStream)localObject).close();
      }
    }
    catch (Exception localException)
    {
      Object localObject = new MessageInf(-33554432, AppLocal.getIntString("message.cannotloadreport"), localException);
      ((MessageInf)localObject).show(this);
      this.jr = null;
    }
  }

  public Object getBean()
  {
    return this;
  }

  protected abstract String getReport();

  protected abstract String getResourceBundle();

  protected abstract BaseSentence getSentence();

  protected abstract ReportFields getReportFields();

  protected EditorCreator getEditorCreator()
  {
    return null;
  }

  public JComponent getComponent()
  {
    return this;
  }

  public void activate()
    throws BasicException
  {
    setVisibleFilter(true);
    this.taxeslogic = new TaxesLogic(this.taxsent.list());
  }

  public boolean deactivate()
  {
	  if( this.reportviewer!=null)  //ati
		  
    this.reportviewer.loadJasperPrint(null);
    return true;
  }

  protected void setVisibleButtonFilter(boolean paramBoolean)
  {
    this.jToggleFilter.setVisible(paramBoolean);
  }

  protected void setVisibleFilter(boolean paramBoolean)
  {
    this.jToggleFilter.setSelected(paramBoolean);
    jToggleFilterActionPerformed(null);
  }

  @SuppressWarnings("all")
private void launchreport()
  {
    this.m_App.waitCursorBegin();
  
	if (this.jr != null)
      try
      {  Object localObject;
        String str = getResourceBundle();
        localObject = this.editor == null ? null : this.editor.createValue();
        JRDataSourceBasic localJRDataSourceBasic = new JRDataSourceBasic(getSentence(), getReportFields(), localObject);
        HashMap localHashMap = new HashMap();
        localHashMap.put("ARG", localObject);
        if (str != null)
          localHashMap.put("REPORT_RESOURCE_BUNDLE", ResourceBundle.getBundle(str));
        localHashMap.put("TAXESLOGIC", this.taxeslogic);
        JasperPrint localJasperPrint = JasperFillManager.fillReport(this.jr, localHashMap, localJRDataSourceBasic);
        
        //reportviewer===com.openbravo.pos.util.JRViewer300
        this.reportviewer.loadJasperPrint(localJasperPrint);
        setVisibleFilter(false);
      }
      catch (MissingResourceException localMissingResourceException)
      {
    	  MessageInf  localObject = new MessageInf(-33554432, AppLocal.getIntString("message.cannotloadresourcedata"), localMissingResourceException);
        ((MessageInf)localObject).show(this);
      }
      catch (JRException localJRException)
      {
    	  MessageInf  localObject = new MessageInf(-33554432, AppLocal.getIntString("message.cannotfillreport"), localJRException);
        ((MessageInf)localObject).show(this);
      }
      catch (BasicException localBasicException)
      {
    	  MessageInf localObject = new MessageInf(-33554432, AppLocal.getIntString("message.cannotloadreportdata"), localBasicException);
        ((MessageInf)localObject).show(this);
      }
    this.m_App.waitCursorEnd();
  }

  private void initComponents()
  {
    this.jPanelHeader = new JPanel();
    this.jPanelFilter = new JPanel();
    this.jPanel1 = new JPanel();
    this.jToggleFilter = new JToggleButton();
    this.jButton1 = new JButton();
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new BorderLayout());
    this.jPanelHeader.setLayout(new BorderLayout());
    this.jPanelFilter.setLayout(new BorderLayout());
    this.jPanelHeader.add(this.jPanelFilter, "Center");
    this.jPanel1.setLayout(new FlowLayout(2));
    this.jToggleFilter.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1downarrow.png")));
    this.jToggleFilter.setSelected(true);
    this.jToggleFilter.setSelectedIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/1uparrow.png")));
    this.jToggleFilter.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JPanelReport.this.jToggleFilterActionPerformed(paramActionEvent);
      }
    });
    this.jPanel1.add(this.jToggleFilter);
    this.jButton1.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/launch.png")));
    this.jButton1.setText(AppLocal.getIntString("Button.ExecuteReport"));
    this.jButton1.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JPanelReport.this.jButton1ActionPerformed(paramActionEvent);
      }
    });
    this.jPanel1.add(this.jButton1);
    this.jPanelHeader.add(this.jPanel1, "South");
    add(this.jPanelHeader, "North");
  }

  private void jButton1ActionPerformed(ActionEvent paramActionEvent)
  {
    launchreport();
  }

  private void jToggleFilterActionPerformed(ActionEvent paramActionEvent)
  {
    this.jPanelFilter.setVisible(this.jToggleFilter.isSelected());
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.reports.JPanelReport
 * JD-Core Version:    0.6.0
 */